package com.rasou.controller;

import com.rasou.constants.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    final RabbitTemplate rabbitTemplate;

    private static Logger logger = LoggerFactory.getLogger(HelloController.class);

    public HelloController(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }


    @GetMapping("/echo")
    public void echo(@RequestParam String msg) {
        logger.info("[echo] : " + msg);
        rabbitTemplate.convertAndSend(Constant.EXCHANGE_NAME, Constant.ROUTING_NAME, msg);
    }
}
